const path = require('path')
const { getCodeAndDepWithPath } = require('./getCodeAndDepWithPath.js')
const getResourceQueue = (entry) => {
    const res = getCodeAndDepWithPath(entry)
    const queue = []
    queue.push(res)
    for (item of queue) {
        const { dependencies, absPath } = item
        item.mapping = {}
        dependencies.forEach((resource) => {
            const resourcePath = path.resolve(path.dirname(absPath), resource)
            const resourceFlie = getCodeAndDepWithPath(resourcePath)
            item.mapping[resource] = resourceFlie.id
            queue.push(resourceFlie)
        })
        item.mapping = JSON.stringify(item.mapping)
    }
    return queue
}

module.exports = {
    getResourceQueue
}